import modelExtend from 'dva-model-extend'
import { model } from '@/common/model/BaseModel'
import { getLabelUse, updateLabel } from '../services/label'

export default modelExtend(model, {
  namespace: 'propLabel',
  state: {
    //
    current: '',
  },
  effects: {
    *fetchSelected(_, { call, put }) {
      // console.log('fetchCheckList')
      const res = yield call(getLabelUse)
      if (res && res.success) {
        yield put({
          type: 'updateState',
          payload: {
            current: res.data.lable,
          },
        })
      }
    },

    *setLabel({ payload }, { put, call }) {
      const res = yield call(updateLabel, payload)
      if (res && res.success) {
        yield put({
          type: 'fetchSelected',
        })
      }
    },
  },
})
